Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuickJs support ESM and add engine->loadFile #91

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yqs112358
Copy link

@yqs112358 yqs112358 commented Feb 6, 2023

使QuickJS可以正常使用ESM的import和export机制。默认的JS_EVAL_GLOBAL不支持ESM,此处修改为JS_EVAL_MODULE,并加载了qjs-libc默认提供的es6 module loader. 经过测试可以完全正常工作。

其次,JS_EVAL_MODULE的行为与JS_EVAL_GLOBAL不同。JS_EVAL_GLOBAL在执行多行JS代码时,会将最后一行代码的返回值作为整个eval调用的返回值,而JS_EVAL_MODULE不会这样。这个也可以理解,因为module是针对文件调用而设计的。
(同样的,python backend的eval和文件加载也具有和上述完全一样的行为)

因此,为了解决这两种 读取文件执行普通eval 语义不同的问题,又联想到 #89 issue,为各引擎增加了一个loadFile函数,针对loadFile的特殊情况进行处理,与普通的eval分开。
不需要特殊处理的引擎的loadFile将读取文件后直接调用eval。

@yqs112358
Copy link
Author

yqs112358 commented Feb 6, 2023

另外需要通过一下这个PR LanderlYoung/ScriptXTestLibs#3
这个PR补充了之前上传时遗漏的qjs-libc头文件。缺失了此头文件会导致github actions的单元测试无法正常编译通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant